import * as types from './types'
import store from '../store/store'
import Recording from 'react-native-recording'

export const start_recording = () => {
    return dispatch => {
        const recording_reducer = store.getState().recording
        if (recording_reducer.started == false) {
            Recording.on('recording', (data) => {
               dispatch(update_stream(data))
            })
        }
        Recording.init(16000, 8192)
        Recording.start()
        dispatch({type: types.START_RECORDING})
    }
}

const update_stream = (stream) => {
    return {type: types.UPDATE_STREAMING, stream: stream}
}

export const stop_recording = () => {
    Recording.stop()
    return {type: types.STOP_RECORDING}
}